package main.java.com.huizluo.stagetwo.phone;

public class NetComboImpl extends NetCombo{

    //private double  moneyPer;//超出部分多少钱每M
    private Integer netFlow;//上网流量，单位byte

    public NetComboImpl(int netFlow,double cost){
        super();
        this.netFlow = netFlow;
        this.costPerMonth = cost;
    }

    public Integer getNetFlow() {
        return netFlow;
    }

    public void ShowAllCombo() {
        System.out.printf("流量套餐包含：%s 资费：%f元\n",NetComboImpl.format(this.netFlow),this.costPerMonth);
    }

    public void online(Integer flow, PhoneCard card) {
        System.out.println("正在上网");
        card.calculateFlow(flow);
    }

    private static String format(Integer flow){
        if (flow < 1024){
            return String.format("%dB",flow);
        }
        if (flow < 1024 * 1024){
            int k = flow / 1024;
            int b = flow % 1024;
            return String.format("%dKB %dB",k,b);
        }


        int m = flow / (1024*1024);
        int k = (flow - (m*1024*1024)) / 1024;
        int b = flow % 1024;
        return String.format("%dMB %dKB %dB",m,k,b);
    }
}
